﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Data;

namespace AbetEvaluation.Business
{
	public partial class Clients : Component
	{
		public Clients()
		{
			InitializeComponent();
		}

		public Clients(IContainer container)
		{
			container.Add(this);

			InitializeComponent();
		}

		public static DataTable GetAllClients()
		{
			Data.DataSet1TableAdapters.ClientsTableAdapter clientsAdapter = new Data.DataSet1TableAdapters.ClientsTableAdapter();
			Data.DataSet1.ClientsDataTable clientsTable = clientsAdapter.GetAllClients();

			Data.DataSet1TableAdapters.RolesTableAdapter rolesAdapter = new Data.DataSet1TableAdapters.RolesTableAdapter();
			Data.DataSet1.RolesDataTable rolesTable = rolesAdapter.GetAllClientRoles();

			foreach (Data.DataSet1.ClientsRow clientRow in clientsTable.Rows)
			{
				foreach (Data.DataSet1.RolesRow roleRow in rolesTable.Rows)
				{
					if (clientRow.UserId.Equals(roleRow.UserId))
					{
						if (String.IsNullOrEmpty(clientRow.Roles))
						{
							clientRow.Roles = roleRow.RoleName;
						}
						else
						{
							clientRow.Roles += "," + roleRow.RoleName;
						}
					}
				}
			}

			return clientsTable;
		}
	}
}
